package com.coolxiaoyao.web.http;

import com.coolxiaoyao.common.exception.UnsupportedMediaTypeException;
import io.netty.handler.codec.http.HttpHeaders;

import java.io.IOException;


/**
 * @author Kerry on 18/09/19
 */

public class HttpHeaderFilter implements IHttpHeaderChainFilter {

    public static final String APPLICATION_JSON = "application/json";


    @Override
    public void filter(HttpHeaders httpHeaders) throws IOException {
        if (httpHeaders == null) {
            return;
        }
        String s = httpHeaders.get("Content-Type");
        if (!APPLICATION_JSON.equals(s)) {
            //落实...
            throw new UnsupportedMediaTypeException("only support application/json");
        }
    }
}
